package io.renren.wechat.controller;

import io.renren.common.utils.R;
import io.renren.wechat.service.suite.SuiteService;
import io.renren.wechat.service.suite.dto.PermanentAuthInfoResponse;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author dmcp@qq.com
 * @since 2021/12/15 22:43
 */
@RestController
@RequestMapping("/wechat/corp")
public class CorpController {
    private static final Logger LOGGER = LoggerFactory.getLogger(UserController.class);
    private SuiteService suiteService;

    @RequestMapping("/{corpId}")
    public R detail(@PathVariable(value = "corpId", required = false) String corpId) {
        if (StringUtils.isBlank(corpId)) {
            return R.error("corpId is required");
        }

        final PermanentAuthInfoResponse corpInfo = suiteService.getCorpInfo(corpId);
        if (null != corpInfo) {
            LOGGER.debug("got corpInfo with corpId: {} corpInfo: {}", corpId, corpInfo);


            return R.ok().put("corpInfo", corpInfo);
        }

        return R.error("corpInfo not found with corpId: [{" + corpId + "}]");
    }

    @Autowired
    public void setSuiteService(SuiteService suiteService) {
        this.suiteService = suiteService;
    }

}
